home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
157_01
/
cmodem.c
< prev
next >
Wrap
Text File
|
1987-10-10
|
31KB
|
1,059 lines
/* HEADER: CUGaaa.bb;
FILENAME: cmodem.c;
TITLE: Xmodem communications in c;
COMPILERS: C86;
SYSTEM: ms-dos;
AUTHORS: Bill Rogers;
VERSION: 5.01;
DATE: 08/04/1985;
KEYWORDS: commnications, xmodem, ms-dos, pc-dos, 8251a, 8530;
SEE-ALSO: local.h;
DESCRIPTION:
"This program implements an elementary version of xmodem for
under ms-dos or pc-dos.";
WARNINGS:
"The zilog usart option is not yet tested.";
*/
/* The calling sequence is:
*
* cmodem
*
* The control sequences are:
*
* <ctrl-z><ctrl-z> send <ctrl-z>
* <ctrl-z>b300 set baud rate to 300 baud
* <ctrl-z>b1200 set baud rate to 12000 baud
* <ctrl-z>d dial telephone number
* <ctrl-z>e exit without hangup
* <ctrl-z>h hangup without exit
* <ctrl-z>i initialize port & baud rate
* <ctrl-z>nx...x enter telephone number x...x
* <ctrl-z>q quit with hangup
* <ctrl-z>rx...x receive file name x...x
* <ctrl-z>sx...x send file name x...x
* <ctrl-z>t trace file transmissions
* <ctrl-z>? display commands
*
* Revision history: Latest revision first.
*
* 12/Dec/84 Changed to C86 (Bill Rogers).
* 04/Jun/82 Removed PMMI defines and ifdef for Australia. Much
* more extensive documentation added. Modem port
* defines now obtained from BDSCIO.H. Code tidied up
* a bit and VARBAUD ifdefs added. Some messages
* changed and numerous small changes ( Bill Bolton).
* ??/???/81 Patched together from existing Cnet and YAM code
* (Steve Passe, Cnode SYSOP, USA).
* SCCS IDENTIFICATION */
static char SCCSID[] = "@(#)cmodem.c 5.0.1";
/*--------------------------------------------------------------------*/
/* INCLUDE */
#define EXTERN extern
#include <local.h>
#undef EXTERN
/*--------------------------------------------------------------------*/
/* DEFINE */
/* Select USART interface type. */
#define OCTAPORT /* Lomas HAZITALL or Lomas OCTAPORT */
/* ascii characters. */
#define NUL 0x00
#define SOH 0x01
#define EOT 0x04
#define ACK 0x06
#define HT 0x09
#define LF 0x0a
#define CR 0x0d
#define NAK 0x15
#define CAN 0x18
#define SUB 0x1a /* ^Z */
#define ESC 0x1b
/* Escape character for control. */
#define ESCCHAR 0x1a /* ^Z */
#ifdef HAZITALL
/* Intel 8253 programmable interval timer definition. */
#define CLOAD 0x8d /* load port. */
#define CCTRL 0x0f /* control port. */
#define CCTRLB 0x76 /* select counter 1,
load lsb, then msb,
square wave generator,
binary counter. */
#define B0300 417 /* 300 baud. */
#define B1200 104 /* 1200 baud. */
/* Intel 8251a serial port definition. */
#define MDATA 0x84 /* Data port. */
#define MSTAT 0x85 /* Status port. */
#define MOMASK 0x01 /* Output ready mask. */
#define MIMASK 0x02 /* Input ready mask. */
#define MCMD1 0x40 /* Internal reset. */
#define MMODE 0x6e /* One stop bit,
even parity,
disable parity,
8 bit character length,
16x baud rate factor. */
#define MCMD2 0x37 /* NA,
internal reset disabled,
rts enabled,
error reset enabled,
break disabled,
receive enabled,
dtr enabled,
send enabled. */
#endif
#ifdef OCTAPORT
/* Zilog 8530 serial port definition, including timer. */
#define B0300 830
#define B1200 206
#define MDATA 0x20 /* Data port. */
#define MSTAT 0x21 /* Status port. */
#define MCMND 0x22 /* Command port. */
#define MOMASK 0x04 /* Output ready mask. */
#define MIMASK 0x01 /* Input ready mask. */
#define MDEFSNUM 10
static unsigned char MDEFS[MDEFSNUM] = {
0x09, /* Select wr09 - master interrupt control. */
0xc0, /* 7-6: force hardware reset.
5-0: - */
0x0f, /* Select wr15 - external status/control. */
0x40, /* 7-0: Disable all interrupts. */
0x04, /* Select wr04 - receiver and transmitter control. */
0x44, /* 7-6: x16 clock,
5-4: 0
3-2: 1 stop bits,
1-1: even parity,
0-0: no parity. */
0x05, /* Select wr05 - transmitter control. */
0xea, /* 7-7: assert dtr,
6-5: transmit 8 bits,
4-4: disable break,
3-3: enable transmit.
2-2: 0
1-1: assert rts.
0-0: - */
0x03, /* Select wr03 - receiver control. */
0xc1 /* 7-6: receive 8 bits,
5-5: no autoenables,
4-1: 0,
0-0: enable receive. */
};
#define MBAUDNUM 10
#define MBAUDLOW 3 /* Index to baudrate low byte. */
#define MBAUDHIGH 5 /* Index to baudrate high byte. */
static unsigned char MBAUD[MBAUDNUM] = {
0x0e, /* Select wr14- miscellaneous control. */
0x00, /* 7-1: -
0-0: Disable baudrate generator. */
0x0c, /* Select wr12 - low byte of baudrate constant. */
11, /* 7-0: 1200 baud. */
0x0d, /* Select wr13 - high byte of baudrate constant. */
0, /* 7-0: 1200 baud. */
0x0b, /* Select wr11 - clock mode control. */
0x56, /* 7-7: no crystal,
6-5: receive clock = baudrate generator output,
4-3: transmit clock = baudrate generator output,
2-2: -
1-0: trxc-out=baudrate generator. */
0x0e, /* Select wr14 - miscellaneous control. */
0x03 /* 7-2: -
1-1: pclk source of clock,
0-0: Enable baudrate generator. */
};
#endif
/* Hayes modem command strings. */
#define ESCAPE_STR "+++"
#define HANGUP_STR "AT H0 \r"
#define DIAL_STR "AT DT "
#define CR_STR "\r"
/* DOS interrupts. */
#define DIR_IO 0x06 /* DOS function request - direct i/o */
#define INPUT 0xff /* DOS function sub-request - accept */
/* Flag values. */
#define OK ( 0)
#define ERROR (-1)
#define WCEOT (-2)
#define TIMEOUT (-3)
#define EMPTY (-4)
#define SECSIZ 128 /* Block size. */
#define RETRYMAX 10
#define PATHLEN 64 /* Send/receive file pathname length */
#define CLKMHZ 8 /* CPU speed in Mhz */
#define TIMECON 311 /* Constant to convert CLKMHZ to ticks.
*/
#define CONSTAT 2
#define CONIN 3
#define NORMAL 0x1c
#define ORIG 0x01
#define ANSWER 0x02
#define READY 0x5f
#define OPT300 0x20
#define OPT600 0x00
#define CLEAR 0x3f
/*--------------------------------------------------------------------